//导入request请求工具
import request from '@/utils/request.js'

//提供调用注册接口的函数
export const userRegisterService = (user) => {
  return request.post('/user/register', user)
}

//提供调用登录接口的函数
export const userLoginService = (user) => {
  return request.post('/user/login', user)
}

//获取用户详细信息
export const userInfoService = () => {
  console.log('调用了获取用户详细信息的接口')
  return request.get('/user/userInfo')
}

//修改用户信息
export const userInfoUpdateService = (userInfo) => {
  return request.put('/user/update', userInfo)
}

//修改头像
export const userAvatarUpdateService=(avatarUrl)=>{
  // let params = new URLSearchParams();
  // params.append('avatarUrl',avatarUrl)
  return request.patch('/user/updateAvatar?avatarUrl='+avatarUrl)
}
//修改密码
// export const userPasswordUpdateService=(oldPwd,newPwd,rePwd)=>{
//   let params = new URLSearchParams();
//   params.append('oldPwd',oldPwd)
//   params.append('newPwd',newPwd)
//   params.append('rePwd',rePwd)
//   return request.patch('/user/updatePwd',params)
// }
// 更新用户密码的服务
export const userPasswordUpdateService = (params, token) => {
    return request.patch('/user/updatePwd', params, {
        headers: {
            'Authorization': `Bearer ${token}`,
            'Content-Type': 'application/json' // 设置 Content-Type 为 application/json
        }
    });
};